﻿using System;
using System.Web.UI;
using SARS.Biz;
using SARS.Entity;

namespace SARS.Course.Group
{
    public partial class StudentGroupDetail : Page
    {
        private readonly GroupBO groupBiz = new GroupBO();
        private readonly UserBO userBiz = new UserBO();
        private GroupEntity group;

        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Cache.SetNoStore();
            if (!string.IsNullOrEmpty(Request.QueryString["gid"]))
            {
                int groupID = Int32.Parse(Request.QueryString["gid"]);

                group = groupBiz.RetrieveGroupById(groupID);
                group.GroupMembers = userBiz.RetrieveStudentByGroupId(groupID);
                group.GroupTutorial = userBiz.RetrieveTutorsByGroupId(groupID);

                hdlabel.Text = group.GroupName;
                lblGroupName.Text = group.GroupName;
                lbGroupCourse.Text = group.Course.CourseInfo;
                lblGroupTutors.Text = group.GroupTutorialNames;

                gvGroupStudent.DataSource = group.GroupMembers;
                gvGroupStudent.DataBind();
            }
            else
            {
                Response.Redirect("Group.aspx");
            }
        }

        protected void btnEdit_OnClick(object sender, EventArgs e)
        {
            Response.Redirect("StudentGroupEdit.aspx?gid=" + group.GroupID);
        }

        protected void btnBackGroup_OnClick(object sender, EventArgs e)
        {
            Response.Redirect("SelectGroupToAssign.aspx");
        }
    }
}